from Products.KnowledgeEngine.KERL.Tokens.ComponentToken import ComponentToken
from Products.KnowledgeEngine.KERL.Operators import *
from Products.KnowledgeEngine.Services.MySQLFiveAssessmentStorageService.MySQLFiveAssessmentStorageService import qstr, qlist
from DateTime import DateTime
   
import types
   
class SearchIndexToken(ComponentToken):
                
    _implements = ComponentToken._implements + ("SearchIndexToken",)
                
    operators = ComponentToken.operators.copy()
                
    def __init__(self, searchIndex, namespace):
        """ Token wraps this object """

        #self.object    = object
        self.object = self
        self.searchIndex = searchIndex
        self.namespace = namespace                        
                
    def toEnglish(self):
        """ Compiles this token into english """
        
        return "Index: %s" % self.searchIndex

    def toSQL( self ):
        
        return """ 
            assessmentIdentity IN (
                SELECT assessmentIdentity 
                FROM answers 
                WHERE searchIndex = %s 
                AND   searchValue  %%s
            )
        """ % ( qstr(self.searchIndex))
                

    def toJavascript( self ):
        
        raise "NotImplemented"

    # -----------------------------------------------------------------------------

    def equals(self, other, assessment):
        """ Overload the Equals operator for Components """
                
        raise "NotImplemented"                
                   
    # -----------------------------------------------------------------------------
        
    def contains(self, other, assessment):            
        """ Overload the contains operator for Components """
        
        raise "NotImplemented"
                    
    # -----------------------------------------------------------------------------
                 
    def toKERL(self):
        return "'idx:%s'" % self.searchIndex
    